/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commons.collections;

import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.ArrayUtils;

/**
 *
 * @author WangShuai
 */
public class Demo1 {

    public static void main(String[] args) {
        //Retrieving Map Values Without Casting
        Object[] mapArray = new Object[][]{
            {"A", new Double(2.0)},
            {"B", new Double(0.223242)},
            {"C", new Double(2828e4)},
            {"D", "GARBAGE"}};

        Map numberMap = ArrayUtils.toMap(mapArray);

        double a = MapUtils.getDoubleValue(numberMap, "A");
        double b = MapUtils.getDoubleValue(numberMap, "B");
        double c = MapUtils.getDoubleValue(numberMap, "C");
        double d = MapUtils.getDoubleValue(numberMap, "D", new Double(Double.NaN));
        System.out.println("A = " + a);
        System.out.println("B = " + b);
        System.out.println("C = " + c);
        System.out.println("D = " + d);
    }
}
